<?php

namespace Abstraction;
use \Entity;

abstract class PqpAbstract
{
    protected
    
    $name,
    $struct;
    
    function __construct()
    {
        $this->doConstruct();
    }
    
    abstract protected function doConstruct();
    abstract protected function translate($data, $alt);
    
    protected function generate($data)
    {
        foreach($data as $key => $val)
        {
            $result [] = sprintf($this->struct[$key], $val);
        }
        
        unset($data, $key, $val);
        return implode('', $result);
    }
    
    public function prepareData($data)
    {
        $result = array();
        while( sizeof($data) > 0)
        {
            $tamp = array_shift($data);
            $alt = (count($data) % 2 === 0)? '' : 'alt';
            $trans = $this->translate($tamp, $alt);
            
            $result [] = $this->generate($trans);
        }
            
        unset($tamp, $alt, $trans, $data);
        if(sizeof($result) > 0) return $result;
    }
}
